// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import Character from "../../BASE/Character";
import ComponentBase from "../../BASE/ComponentBase";
import realThing from "../../BASE/realThing";
import { gif } from "../../BASE/spineANDgif/gif";
import SXX from "../../Scharacter/SXX";
import mouse from "../mouse";
import { JNFU } from "./JNFU";

const {ccclass, property} = cc._decorator;

@ccclass
export default class FDUIs extends ComponentBase {
target:realThing=null
sarget:SXX=null
n:number=0
TK:string[]=["EQM","ZDM","JNM"]
Tname:cc.Label=null
TKP:cc.Vec3[]=[cc.v3(0,-110),cc.v3(0,-122),cc.v3(0,-110)]
TtX:gif=null
    start() {
        // 注册鼠标点击事件
        this.node.on(cc.Node.EventType.MOUSE_DOWN, this.onMouseDown, this);
      //this.sarget=this.node.parent.getComponent(realThing)
       

    }
   X(){    this.node.active = false;  this.node.scale =1; this.node.position=this.target.node.position}
    onMouseDown(event: cc.Event.EventMouse) {
        // 获取点击位置的世界坐标
        const worldPoint = event.getLocation();
    
        // 获取节点的世界坐标系下的包围盒
        const boundingBox = this.node.getBoundingBoxToWorld();
    console.log(boundingBox.contains(worldPoint))
        // 判断点击位置是否在节点的边界内
        console.log(event.getButton() == cc.Event.EventMouse.BUTTON_LEFT)
            // 判断是否为左键点击
            if (event.getButton() == cc.Event.EventMouse.BUTTON_LEFT&&!boundingBox.contains(worldPoint)) { // 0 表示左键
                // 左键点击事件，设置标签并放大节点
                cc.find("Canvas").getComponent(mouse).n+=1
               this.node.zIndex+=cc.find("Canvas").getComponent(mouse).n



            } else if (event.getButton() == cc.Event.EventMouse.BUTTON_RIGHT&&boundingBox.contains(worldPoint)) { // 2 表示右键
                // 右键点击事件，只放大节点
                cc.find("Canvas").getComponent(mouse).n+=1
                this.node.zIndex+=cc.find("Canvas").getComponent(mouse).n
                this.node.scale *= 1.2;
            }
            event.stopPropagation()
    }

toL(){
if (this.n==0) {
    this.n=2
}else{this.n-=1}
for (let index = 0; index <= 2; index++) {
   if (this.n==index) {
    this.node.getChildByName("star").children[index].active=true
   }else{   this.node.getChildByName("star").children[index].active=false}
    
}
this.node.getChildByName(this.TK[this.n]).active=true
this.J()

}

toR(){
    this.node.getChildByName(this.TK[this.n]).active=false
    this.node.getChildByName(this.TK[this.n]).opacity=0
    if (this.n==2) {
        this.n=0
    }else{this.n+=1}
    for (let index = 0; index <= 2; index++) {
        if (this.n==index) {
         this.node.getChildByName("star").children[index].active=true
        }else{   this.node.getChildByName("star").children[index].active=false;}
         
     }
     this.node.getChildByName(this.TK[this.n]).active=true
     this.J()


 

    }
J(){
if (this.TK[this.n]=="ZDM") {
    this.ZDSX()
}
if (this.TK[this.n]=="JNM") {
   // this.ZDSX()
}
if (this.TK[this.n]=="EQM") {
   // this.ZDSX()
}

    let o=this.node.getChildByName(this.TK[this.n])
    const k=this.TKP[this.n]
cc.tween(o)
.to(0.2, { opacity: 255})
.to(0.1, { position: cc.v3(k.x+ 5,k.y+5) }, { easing: "sineInOut" })
.to(0.1, { position: cc.v3(k.x-5,k.y-5) }, { easing: "sineInOut" })
.to(0.1, { position: k }, { easing: "sineInOut" })

.start()

this.showAndShakeChildren2(o,0.3,7)
   

//this.shakeNodehh(,0.3,20)


}



ZDSX(){
if (this.target instanceof Character) {
    

for(let a of this.node.getChildByName("ZDM").children){

    a.children[0].getComponent(cc.RichText).string=this.target.getZDSX(a.name)

}

}
}

JNSX(){
    if (this.target instanceof Character) {
        
    
    for(let a of this.node.getChildByName("JNM").children){
    
      //  a.children[0].getComponent(cc.RichText).string=this.target.getZDSX(a.name)
    
    }
    this.node.getChildByName("JNJSB").getChildByName("JNFU").getComponent(JNFU).setupRichText(this.sarget.SJNC[0])
    }

   


}



JND(n:number){


    this.node.getChildByName("JNJSB").getChildByName("JNFU").getComponent(JNFU).setupRichText(this.sarget.SJNC[n])
}
}
